package com.yifeng.repo.base.utils.redis.client;

import redis.clients.jedis.Jedis;

/**
 * One solution is try-with-resource of java 7 (Jedis is implement from Closeable), another is abstract class
 * Created by daibing on 2020/2/18.
 */
public abstract class AbstractJedisCommand<T> {
    public final T doExecute(JedisClient jedisClient) {
        Jedis jedis = null;
        try {
            jedis = jedisClient.get();
            return this.doRun(jedis);
        } finally {
            jedisClient.close(jedis);
        }
    }

    protected abstract T doRun(Jedis jedis);
}
